//////////////////////////////////////
// Fast Container Library           //
// MIT License - Copyright (c) 2012 //
//////////////////////////////////////

#pragma once

#include "algobase.h"
#include "bit_base.h"

FC_NAMESPACE_BEGIN


template <size_t N>
class static_bit_array
{
public:
	typedef size_t						size_type;
	typedef static_bit_array			this_type;
	typedef bit_reference				reference;

	enum : size_t
	{
		NWords = (((N - 1) / 32) + 1),
		size_bits = 32,
		size_mask = 31,
		size_shift = 5
	};

	static_bit_array()
		{
			reset();
		}

	reference operator[]( size_t pos ) { return reference( &m_bits[pos >> size_shift], pos & size_mask ); }
	bool operator []( size_t pos ) const { return (m_bits[pos >> size_shift] & pos) != 0; }

	bool get( size_t pos ) const { return operator[](pos); }
	bool test( size_t pos ) const { return operator[](pos); }

	void flip( size_t pos ) { operator[](pos) ^= true; }
	void set( size_t pos, bool value ) { operator[](pos) = value; }

	void reset()
	{
		::memset( m_bits, 0, NWords * sizeof(int) );
	}

	size_t size() const { return N; }

	size_t* data() { return m_bits; }
	const size_t* data() const { return m_bits; }

	void swap( this_type& x )
	{
		fc::swap( *this, x );
	}

protected:
	size_t m_bits[NWords];
};



template <size_t N> inline
	bool operator ==( const static_bit_array<N>& a, const static_bit_array<N>& b )
	{
		return( &a == &b || fc::equal(a.begin(), a.end(), b.begin()) );
	}

template <size_t N> inline
	bool operator !=( const static_bit_array<N>& a, const static_bit_array<N>& b )
	{
		return !(a == b);
	}



FC_NAMESPACE_END
